package org.extreme.model.base;

import org.extreme.base.Style;
import org.extreme.model.dom.XElement;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;

@Root
public class ObjectElement implements XElement {
	@Element
	private Object value;
	
	private Style style;
	
	public ObjectElement(@Element(name="value") Object value) {
		this.value = value;
	}

	public void setValue(Object value) {
		this.value = value;
	}

	public Object getValue() {
		return value;
	}

	public void setStyle(Style style) {
		this.style = style;
	}

	public Style getStyle() {
		return style;
	}

	public int hashCode() {
		return this.value == null ? 0 : this.value.hashCode();
	}

	public boolean equals(Object obj) {
		if (obj == this) {
			return true;
		}
		
		if (! (obj instanceof ObjectElement)) {
			return false;
		}
		
		ObjectElement objectElement = (ObjectElement)obj;
		
		return this.value == null ? objectElement.value == null : this.value.equals(objectElement.value)
				&& this.style == null ? objectElement.style == null : this.style.equals(objectElement.style);
	}
	
	public String toString() {
		return value == null ? "null" : value.toString();
	}
}
